package com.gardenguell.salad.ui.adapter;

import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.RecyclerView.ViewHolder;
import android.view.View;
import com.gardenguell.salad.data.model.BaseModel;

/**
 * Created by absurd on 16/2/10.
 */
public abstract class ClickableRecyclerViewAdapter<VH extends ViewHolder>
        extends RecyclerView.Adapter<VH> implements View.OnClickListener, View.OnLongClickListener{

    protected OnRecyclerViewItemClickListener mOnRecyclerViewItemClickListener = null;
    protected OnRecyclerViewItemLongClickListener mOnRecyclerViewItemLongClickListener = null;

    public void setOnRecyclerViewItemClickListener(OnRecyclerViewItemClickListener listener){
        this.mOnRecyclerViewItemClickListener = listener;
    }

    public void setOnRecyclerViewItemLongClickListener(OnRecyclerViewItemLongClickListener listener){
        this.mOnRecyclerViewItemLongClickListener = listener;
    }

    public interface OnRecyclerViewItemLongClickListener {
        public boolean onItemLongClicked(View view, BaseModel baseModel);
    }


    public interface OnRecyclerViewItemClickListener{
        void onItemClick(View view, BaseModel baseModel);
    }

    @Override
    public void onClick(View v) {
        if(mOnRecyclerViewItemClickListener != null){
            mOnRecyclerViewItemClickListener.onItemClick(v, (BaseModel)v.getTag());
        }
    }

    @Override
    public boolean onLongClick(View v) {
        if(mOnRecyclerViewItemLongClickListener != null){
            mOnRecyclerViewItemLongClickListener.onItemLongClicked(v, (BaseModel)v.getTag());
        }
        return true;
    }
}
